public class Leetcode2645 {
    public static void main(String[] args) {
        System.out.println(addMinimum("b"));
        System.out.println(addMinimum("aaa"));
        System.out.println(addMinimum("abc"));
    }
    public static int addMinimum(String word) {
        char[] charArray = word.toCharArray();

        int res = 0;

        char[] chars = new char[]{'a', 'b', 'c' };
        int index = 0;
        for (int i = 0; i < charArray.length; i++) {
            if (charArray[i] == chars[index]) {
                index++;
            } else {
                //借一个
                res++;
                index++;
                i--;
            }

            index = index % 3;
        }
        if (index == 0) {

        } else if (index == 1) {
            res += 2;
        } else {
            res++;
        }

        return res;
    }
}
